﻿using System;
using System.Text;
using System.Web.UI;
using HiauPdm.Bll;
using System.Reflection;
using System.Web;

namespace HiauPdm.Web
{
    public class PageBase : Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            Response.Expires = -1;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetNoStore();
            if (Session["RealName"] == null)
            {
                Response.Redirect(string.Format("~/Login.aspx?ReturnUrl={0}", Server.UrlEncode(Request.Url.PathAndQuery)));
            }
            if (!IsAccess())
            {
                Response.Redirect("~/Login.aspx");
            }
        }

        protected virtual bool IsAccess()
        {
            return IsAccess(Request.Path.Substring(Request.Path.LastIndexOf("/WebApp/") + 8));
        }

        protected bool IsAccess(string sModule)
        {
            return BMain.CheckAccess(sModule, (int)Session["UserId"]);
        }

        protected void MsgBox(string sMsg, bool bRefresh)
        {
            if (bRefresh)
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "ShowMsgBox", "window.attachEvent('onload',function(){self.location.replace(self.location);alert('" + sMsg + "');});", true);
            else
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "ShowMsgBox", "window.attachEvent('onload',function(){alert('" + sMsg + "');});", true);
        }

        protected void MsgBox(string sMsg)
        {
            MsgBox(sMsg, false);
        }

        protected bool ShowErr(string sErrMsg)
        {
            if ((sErrMsg != null) && (sErrMsg != string.Empty))
            {
                MsgBox(sErrMsg, false);
                return true;
            }
            return false;
        }
    }
}
